/**
 * The SimplePanelTag user-interface tag conversor class
 * This component have two classes to handle it, according to the new syslib best practices. 
 * The first class create the component itself, and can be called and handled by javascript code instead of tags only.
 * The second class (with the suffix Tag) convert the tag into the component.
 * @class syslib.ui.SimplePanelTag
 * @author Gabriel Ricci
 */
syslib.ui.SimplePanelTag = __class(syslib.ui.VisualTag, 
/** 
 * @lends syslib.ui.SimplePanelTag
 */
{
	panel : null,
	
	prepare : function(){
		// nothing to do, just return
		return true;
	},

	execute : function(){
		// create the dialog
		this.panel = new syslib.ui.SimplePanel({
			target: false, 
			title : (__valid(this.__attributes.title)) ? this.__attributes.title : "",  
			content : this.__innerHTML, 
			style : (__valid(this.__attributes.style)) ? this.__attributes.style : ""
		});
		
		// set the element
		this.__element = this.panel.getElement();
		
		// return the dialog element
		return this.__element;
	},

	finalize : function(){
		// return
		return true;	
	}
});

/**
 * The Dialog user-interface component class]
 * @class syslib.ui.SimplePanel
 * @author Gabriel Ricci
 */
syslib.ui.SimplePanel = __class();
syslib.ui.SimplePanel.prototype = {
	_options : null, 
	_element : null, 
	_references : null, 
	
	__construct : function(options){
		// set the default options
		this._options = __extend({
			id : null,  
			title : "Dialog",
			target  : null, 
			content : "", 
			style : "" 
		}, options);
	
		// load the style
		syslib.loadStyleForComponent("simplepanel");
		
		// check the id
		if(!__valid(this._options.id)){this._options.id = syslib.element.generateID();}
		
		// create the element
		this.createElement();
	}, 
	
	createElement : function(){
		// create the structure
		var elemtJSON = ["div", {"id" : this._options.id, "style" : this._options.style, "class" : "syslib-border-radius syslib-simplepanel-container"},
			["div", {"class" : "syslib-title-text syslib-simplepanel-title", "innerName" : "title"}, this._options.title],
			["div", {"class" : "syslib-text syslib-simplepanel-body", "innerName" : "body"}, this._options.content]
		];
		
		// create the object
		var objectData 	= syslib.element.createFromJSON(false, elemtJSON);
		this._element	= objectData.element;
		this._references	= objectData.references;
		
		// create the events
		syslib.event.listen("click", this._references.title, function(){
			syslib.element.toggleVisibility(this._references.body);
		}.applyTo(this));
 	}, 
 	
 	append : function(){
 		// append
 		if(__valid(this.options.target)){
 			this.options.target.appendChild(this.element);
 		}
 	}, 
 	
 	getElement : function(){
 		return this._element;
 	}
};